package cn.cvs.servlet;

import cn.cvs.dao.ResumeDao;
import cn.cvs.utils.MyBatisUtil;
import com.alibaba.fastjson.JSON;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int count = sqlSession.getMapper(ResumeDao.class).delete(id);
        String rows = JSON.toJSONString(count);
        PrintWriter out = resp.getWriter();
        out.print(rows);
        out.flush();
        out.close();
        MyBatisUtil.closeSqlSession(sqlSession);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
